//
//  mainViewController.m
//  demo3
//
//  Created by 张仕儒 on 2021/7/7.
//

#import "mainViewController.h"
//#import "hoverButton.h"
#import "TableView.h"

@interface mainViewController ()
@property (weak) IBOutlet NSButton *tabBtn1;
@property (weak) IBOutlet NSButton *tabBtn2;
@property (weak) IBOutlet NSBox *tabUnderLine1;
@property (weak) IBOutlet NSBox *tabUnderLine2;
@property (weak) IBOutlet NSButton *cateDownArrow;
@property (weak) IBOutlet NSButton *developDownArrow;
@property (weak) IBOutlet NSBox *bottomBar;
@property (weak) IBOutlet NSBox *tipBox;
@property (weak) IBOutlet NSBox *tableBox;
@property (weak) IBOutlet NSBox *cateBox;
@property (weak) IBOutlet NSBox *deveBox;
@property (weak) IBOutlet NSBox *searchBar;
@property (weak) IBOutlet NSBox *selectBox;
@property (weak) IBOutlet NSBox *deletBox;
@property (weak) IBOutlet NSBox *operationBox;
@property (weak) IBOutlet NSButton *cancelBtn;
@property (weak) IBOutlet NSButton *removeBtn;
@property (weak) IBOutlet NSBox *believeBox;
@property (weak) IBOutlet NSBox *patchOperationBox;


@end

@implementation mainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    _tabView.delegate = self;
    TableView *table = [TableView initWithNibName:@"TableView"];
    [table initView];
    self.tableBox.contentView = table;
    [self setInitUi];
    
}

- (void)setInitUi {
    self.tabBtn1.contentTintColor = [NSColor blackColor];
    [self.tabUnderLine1 setFillColor:[NSColor systemBlueColor]];
    [self.tabUnderLine1 setBorderWidth: 5.0];
    _removeBtn.wantsLayer = YES;
    _removeBtn.layer.backgroundColor = [NSColor systemBlueColor].CGColor;
//    [self.cancelBtn setButtonType:NSBezelStyleRoundRect];
    NSMutableAttributedString *attrTitle = [[NSMutableAttributedString alloc]initWithAttributedString:[self.cancelBtn attributedTitle]];
    NSUInteger len = [attrTitle length];
    NSRange range = NSMakeRange(0, len);
 
    [attrTitle addAttribute:NSForegroundColorAttributeName
                      value:[NSColor systemBlueColor]
                      range:range];
 
    [attrTitle fixAttributesInRange:range];
 
    //改变按键的富文本
    [self.cancelBtn setAttributedTitle:attrTitle];
}

- (IBAction)changeTabStyle:(id)sender {
    if (sender == self.tabBtn2) {
        self.tabBtn2.contentTintColor = [NSColor blackColor];
        self.tabBtn1.contentTintColor = [NSColor systemGrayColor];
        self.tabUnderLine1.borderColor = [NSColor systemGrayColor];
        self.tabUnderLine2.borderColor = [NSColor systemBlueColor];
    }else{
        self.tabBtn1.contentTintColor = [NSColor blackColor];
        self.tabBtn2.contentTintColor = [NSColor systemGrayColor];
        self.tabUnderLine1.borderColor = [NSColor systemBlueColor];
        self.tabUnderLine2.borderColor = [NSColor systemGrayColor];
    }
}

- (IBAction)openFileDialog:(NSButton *)sender {
    NSLog(@"click");
    NSOpenPanel* openDlg = [NSOpenPanel openPanel];
    [openDlg setCanChooseFiles:YES];
    [openDlg setCanChooseDirectories:NO];
    [openDlg setAllowsMultipleSelection:NO];
    [openDlg setPrompt:@"Select"];
    if ([openDlg runModal] == NSOKButton) {
        for(NSURL* URL in [openDlg URLs]) {
            NSLog( @"%@", [URL path] );
        }
    }
}
- (IBAction)showCategory:(id)sender {
    [self.deveBox setHidden:YES];
    [self.developDownArrow setImage:[NSImage imageNamed:@"NSTouchBarGoDownTemplate"]];
//    [self.cateBox isTransparent];
    if(_cateBox.isHidden){
        [self.cateBox setHidden:NO];
        [self.cateDownArrow setImage:[NSImage imageNamed:@"NSTouchBarGoUpTemplate"]];
    }else {
        [self.cateBox setHidden:YES];
        [self.cateDownArrow setImage:[NSImage imageNamed:@"NSTouchBarGoDownTemplate"]];
    }
}
- (IBAction)showDeveloper:(id)sender {
    [self.cateBox setHidden:YES];
    [self.cateDownArrow setImage:[NSImage imageNamed:@"NSTouchBarGoDownTemplate"]];
    if(_deveBox.isHidden) {
        [self.deveBox setHidden:NO];
        [self.developDownArrow setImage:[NSImage imageNamed:@"NSTouchBarGoUpTemplate"]];
    }else {
        [self.deveBox setHidden:YES];
        [self.developDownArrow setImage:[NSImage imageNamed:@"NSTouchBarGoDownTemplate"]];
    }
}


- (IBAction)showTips:(id)sender {
    if(_tipBox.isHidden) {
        [self.tipBox setHidden:NO];
    }else {
        [self.tipBox setHidden:YES];
    }
}

- (IBAction)showSearch:(id)sender {
    if(_searchBar.isHidden) {
        [self.searchBar setHidden:NO];
        [self.selectBox setHidden:YES];
    }
}

- (IBAction)showSelect:(id)sender {
    if(_selectBox.isHidden) {
        [self.selectBox setHidden:NO];
        [self.searchBar setHidden:YES];
    }
}
- (IBAction)hideDelet:(id)sender {
    [self.deletBox setHidden:YES];
    [self.operationBox setHidden:NO];
}
- (IBAction)showDeleteBox:(id)sender {
    [self.deletBox setHidden:NO];
    [self.operationBox setHidden:YES];
}

- (IBAction)patchOperation:(id)sender {
    [self.believeBox setHidden:NO];
    [self.patchOperationBox setHidden:YES];
}
- (IBAction)hideOperation:(id)sender {
    [self.believeBox setHidden:YES];
    [self.patchOperationBox setHidden:NO];
}



@end



